<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Web.Models.ViewData.DinnerFormViewModel>" %>

    <%= Html.ValidationSummary("Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) {%>

        <fieldset>

            <div id="dinnerDiv"> 

                <p>
                    <label for="Title">Title:</label>
                    <%= Html.TextBox("Title", Model.Dinner.Title, new { size = 40, @class = "myClass" })%>
                    <%= Html.ValidationMessage("Title", "*") %>
                </p>
                <p>
                    <label for="EventDate">EventDate:</label>
                    <%= Html.TextBox("EventDate", String.Format("{0:g}", Model.Dinner.EventDate))%>
                    <%= Html.ValidationMessage("EventDate", "*") %>
                </p>
                <p>
                    <label for="Description">Description:</label>
                    <%= Html.TextArea("Description", Model.Dinner.Description)%>
                    <%= Html.ValidationMessage("Description", "*") %>
                </p>
                <p>
                    <label for="ContactPhone">ContactPhone:</label>
                    <%= Html.TextBox("ContactPhone", Model.Dinner.ContactPhone)%>
                    <%= Html.ValidationMessage("ContactPhone", "*") %>
                </p>
                <p>
                    <label for="Address">Address:</label>
                    <%= Html.TextBox("Address", Model.Dinner.Address)%>
                    <%= Html.ValidationMessage("Address", "*") %>
                </p>
                <p>
                    <label for="Country">Country:</label>
                    <%= Html.DropDownList("Country", Model.Countries) %>
                    <%= Html.ValidationMessage("Country", "*") %>
                </p>
                <%= Html.Hidden("Latitude", Model.Dinner.Latitude)%> 
                <%= Html.Hidden("Longitude", Model.Dinner.Longitude)%>
                <p>
                    <input type="submit" value="Save" />
                </p>
            </div>
            
            <div id="mapDiv">     
                <% Html.RenderPartial("Map", Model.Dinner); %> 
            </div> 
            
        </fieldset>
        
        <script type="text/javascript">

            $(document).ready(function() {
            $("#Address").blur(function(evt) {
                UpdateMap()
                }); 
            });

            $(document).ready(function() {
            $("#Country").change(function(evt) {
                UpdateMap()
                });
            });

            function UpdateMap() {
                //If it's time to look for an address, 
                // clear out the Lat and Lon
                $("#Latitude").val("");
                $("#Longitude").val("");

                var address = jQuery.trim($("#Address").val()) + ", " + jQuery.trim($("#Country").val());
                if (address.length == 0)
                    return;

                FindAddressOnMap(address);
            }         
                      
        </script>

    <% } %>